Implement I/O seek()
fn seek() {
let dir = TmpBuilder::new().prefix("tokio-fs-tests").tempdir().unwrap();
let file_path = dir.path().join("seek.txt");
let pool = Builder::new().pool_size(1).build();
let (tx, rx) = oneshot::channel();
pool.spawn(
OpenOptions::new()
.create(true)
.read(true)
.write(true)
.open(file_path)
.and_then(|file| io::write_all(file, "Hello, world!"))
.and_then(|(file, _)| file.seek(SeekFrom::End(-6)))
.and_then(|(file, _)| io::read_exact(file, vec![0; 5]))
.and_then(|(file, buf)| {
assert_eq!(buf, b"world");
file.seek(SeekFrom::Start(0))
})
.and_then(|(file, _)| io::read_exact(file, vec![0; 5]))
.and_then(|(_, buf)| {
assert_eq!(buf, b"Hello");
Ok(())
})
.then(|r| {
let _ = r.unwrap();
tx.send(())
}),
);
rx.wait().unwrap();
}